<template>
  <div class="my">
    <div class="myHead">
      <div class="head_box">
        <van-image
          class="portrait"
          @click="$router.push('/info')"
          :src="userInfo.photo"
        >
          <template v-slot:error>
            <img class="portrait" src="@/assets/隐忍.png" alt="" />
          </template>
        </van-image>

        <!-- :src="userInfo.photo" -->
        <div class="right">
          <div class="username">{{ userInfo.name }}</div>
          <div class="status">
            <span v-if="userInfo.is_media === false">申请认证</span>
            <span v-else>普通会员</span>
          </div>
        </div>
      </div>
      <div class="head_items">
        <div class="item">
          <div class="num">{{ userInfo.art_count }}</div>
          <div class="txt">动态</div>
        </div>
        <div class="item">
          <div class="num">{{ userInfo.follow_count }}</div>
          <div class="txt">关注</div>
        </div>
        <div class="item">
          <div class="num">{{ userInfo.fans_count }}</div>
          <div class="txt">粉丝</div>
        </div>
      </div>
      <div class="items">
        <div class="item">
          <van-icon class="item_icon r" name="star-o" />
          <div class="txt">收藏</div>
        </div>
        <div class="item center">
          <van-icon class="item_icon o" name="clock-o" />
          <div class="txt">历史</div>
        </div>
        <div class="item">
          <van-icon class="item_icon b" name="records" />
          <div class="txt">作品</div>
        </div>
      </div>
      <div class="reading">
        <van-icon class="readingIcon" name="underway-o" />
        <div class="readingRight">
          <p>今日阅读</p>
          <p>5分钟</p>
        </div>
      </div>
    </div>
    <div class="myBody">
      <div class="cell1">
        <myCell class="top-b" icon="volume-o" title="消息通知"></myCell>
        <myCell class="bottom-b" icon="credit-pay" title="实名认证"></myCell>
      </div>
      <div class="cell2">
        <myCell class="top-b" icon="comment-o" title="用户反馈"></myCell>
        <myCell
          icon="smile-o"
          title="在线咨询"
          @click.native="$router.push('/chat')"
        ></myCell>
        <myCell class="bottom-b" icon="setting-o" title="系统设置"></myCell>
      </div>
      <van-button
        class="logout"
        block
        type="info"
        native-type="submit"
        @click="logout"
      >
        登 出
      </van-button>
    </div>
  </div>
</template>

<script>
import myCell from './myCell'
import { apiGetUser } from '@/api/use.js'
import { mapState } from 'vuex'
import { localDel } from '@/utils/mylocal.js'
export default {
  components: {
    myCell
  },
  data () {
    return {
      myList: {}
    }
  },
  methods: {
    initMy () {
      apiGetUser()
        .then(res => {
          console.log(res)
          this.myList = res.data.data
          this.$store.commit('setUserInfo', this.myList)
        })
        .catch(() => {
          this.$router.push('/login?next=/my')
        })
    },
    logout () {
      this.$dialog
        .confirm({
          title: '登 出',
          message: '是否要登出?'
        })
        .then(() => {
          localDel('token')
          this.$store.commit('setIsLogin', false)
          this.$router.push('/login')
        })
        .catch(() => {})
    }
  },
  created () {
    this.initMy()
  },
  computed: {
    ...mapState(['userInfo'])
  }
}
</script>

<style lang="less" scoped>
.my {
  background: #f5f7f9;
  height: calc(100% - 50px);
  .myHead {
    width: 100%;
    height: 225px;
    // opacity: 0.7;
    padding: 40px 15px 0px;
    background: #e33f3e;
    box-sizing: border-box;
    position: relative;
    .items {
      margin-top: 22.5px;
      display: flex;
      justify-content: center;
      background-color: #fff;
      padding: 12.5px 0px;
      border-radius: 10px;
      .center {
        border-left: 1px solid #edeff3 !important;
        border-right: 1px solid #edeff3 !important;
      }
      .item {
        text-align: center;
        width: 33.3%;

        .item_icon {
          font-size: 20px;
        }
        .r {
          color: #eb5253;
        }
        .o {
          color: #ff9d1d;
        }
        .b {
          color: #678eff;
        }
        .txt {
          font-size: 14px;
          font-family: Microsoft YaHei Regular, Microsoft YaHei Regular-Regular;
          font-weight: 400;
          color: #333333;
          letter-spacing: 1px;
          word-spacing: 20px;
        }
      }
    }
    .head_box {
      display: flex;
      ::v-deep .portrait {
        overflow: hidden;
        width: 65px;
        height: 65px;
        border-radius: 50%;
        border: 1px solid #fff;
      }
      .right {
        padding-top: 15px;
        padding-left: 15px;
        .username {
          font-size: 15px;
          font-family: Microsoft YaHei Regular, Microsoft YaHei Regular-Regular;
          font-weight: 400;
          text-align: left;
          color: #ffffff;
          letter-spacing: 1px;
        }
        .status {
          margin-top: 10px;
          width: 60px;
          height: 16px;
          line-height: 16px;
          background: #ffffff;
          border-radius: 8px;
          font-size: 5px;
          font-family: Microsoft YaHei Bold, Microsoft YaHei Bold-Bold;
          font-weight: 700;
          text-align: left;
          color: #e24141;
          letter-spacing: 1px;
          text-align: center;
        }
      }
    }
    .head_items {
      padding: 22.5px 30px 0px;
      display: flex;
      justify-content: space-between;
      .item {
        .num {
          font-size: 15px;
          font-family: Arial Regular, Arial Regular-Regular;
          font-weight: 400;
          color: #ffffff;
          letter-spacing: 1px;
          text-align: center;
        }
        .txt {
          font-size: 15px;
          font-family: Microsoft YaHei Regular, Microsoft YaHei Regular-Regular;
          font-weight: 400;
          text-align: center;
          color: #ffffff;
          letter-spacing: 1px;
        }
      }
    }
    .reading {
      width: 94px;
      height: 40px;
      background: rgba(255, 255, 255, 0.2);
      border-top-left-radius: 20px;
      border-bottom-left-radius: 20px;
      position: absolute;
      right: 0px;
      top: 50px;
      z-index: 1888;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #fff;
      .readingIcon {
        margin-right: 10px;
        font-size: 18px;
      }
      p {
        margin: 0 !important;
        font-size: 12px;
      }
    }
  }
  .myBody {
    padding: 15px;
    margin-top: 46px;
    .cell1 {
      margin-top: 5px;
    }
    .cell2 {
      margin-top: 17px;
    }
    .top-b {
      border-top-left-radius: 10px;
      border-top-right-radius: 10px;
    }
    .bottom-b {
      border-bottom-left-radius: 10px;
      border-bottom-right-radius: 10px;
    }
    .logout {
      border-radius: 10px;
      margin-top: 20px;
      background-color: #e24141;
      border: 0px;
    }
  }
}
</style>
